<!--   @author  Created By  YS  on 2023/11/12 -->
<!--   @describe -->

<template>
  <view :class="[`${PREFIX}`]">
    <textarea name="" :value="msg" id="" cols="30" rows="10" placeholder="填写的越详细，越可能被采纳哦" @input="change"></textarea>
    <view :class="[`${PREFIX}-tip1`]">还可输入{{ restLength }}个字</view>
    <view :class="[`${PREFIX}-imgs`]">
      <view :class="[`${PREFIX}-imgs-items`]" v-for="(item,index) in imgList" :key="index">
        <image :class="[`${PREFIX}-imgs-items-item`]" :src="item" mode=""></image>
        <image :class="[`${PREFIX}-imgs-items-delete`]" src="" mode="" @click="deleteImg(index)"></image>
      </view>
      <view :class="[`${PREFIX}-imgs-items-item`]">
        <image v-if="imgList.length<9" :class="[`${PREFIX}-imgs-add`]" src="" mode="" @click="chooseImg"></image>
      </view>

    </view>


    <view @click="publish">
      发布
    </view>
  </view>
</template>

<script>
  const PREFIX = 'home-material'
  export default {
    data() {
      return {
        PREFIX,
        restLength: 1000,
        imgList: [],
        msg: ''
      }
    },
    methods: {
      change(e) {
        let value = e.detail.value
        this.msg = value
        this.restLength = 1000 - value.length
      },
      chooseImg() {
        uni.chooseImage({
          count: 9,
          success: ({
                      tempFilePaths
                    }) => {
            console.log(tempFilePaths);
            this.imgList = this.imgList.concat(tempFilePaths)
          }
        })
      },
      deleteImg(i) {
        console.log(i);
        let imgListCopy = [...this.imgList]
        imgListCopy.splice(i, 1)
        this.imgList = imgListCopy
      },
      publish() {
        // uni.redirectTo({
        // 	url: '/pages/home/reportRes'
        // })
      }
    }
}
</script>

<style lang="less">
page {
  background: #fff;
}

.home-material {
  padding: 0 34rpx;

  textarea {
    padding-top: 20rpx;
  }

  &-tip1 {
    height: 50rpx;
    line-height: 50rpx;
    color: #999999;
    text-align: right;
    font-size: 36rpx;
  }

  &-tip2 {
    height: 50rpx;
    line-height: 50rpx;
    color: #000000;
    text-align: left;
    font-size: 36rpx;
    margin-top: 22rpx;
  }

  &-imgs {
    display: flex;
    flex-wrap: wrap;
    margin-top: 18rpx;

    &-add {
      width: 218rpx;
      height: 218rpx;
      background: blue;
    }

    &-items {
      width: 218rpx;
      height: 218rpx;
      position: relative;
      margin-right: 8rpx;
      margin-bottom: 8rpx;
      &:nth-child(3n) {
        margin-right: 0;
      }

      &-delete {
        width: 40rpx;
        height: 40rpx;
        background: blue;
        position: absolute;
        top: 18rpx;
        right: 18rpx;
      }

      &-item {
        width: 218rpx;
        height: 218rpx;
        border-radius: 20rpx;
      }
    }
  }


}
</style>
